package com.hengpeng.itfints.controller.activity;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hengpeng.common.exception.ServiceResult;
import com.hengpeng.common.util.StringHelper;
import com.hengpeng.itfinbase.en.RewardRebateStatus;
import com.hengpeng.itfinbase.persist.RewardRebate;
import com.hengpeng.itfinbase.persist.UserInfo;
import com.hengpeng.itfints.controller.BaseController;
import com.hengpeng.itfints.tools.PageUtil;
import com.hengpeng.itfints.vo.MemberSession;

/**
 * 邀请返利控制类
 * @author lugaofei 20151026
 *
 */
@Controller
@RequestMapping(value="/rebate")
public class RewardRebateController extends BaseController {
    /**
     * 获取返利列表
     */
    @RequestMapping(value = "list")
    public String getRebateList(HttpServletRequest request,ModelMap map,RewardRebateStatus status,String curPage,String startTime,String endTime){
        MemberSession session = getSessionMember(request);
        if (session == null) {
            return "/page/login/login.jsp";
        }
        int int_curPage = (!StringHelper.isEmpty(curPage) ? Integer.parseInt(curPage) : 1);
        UserInfo userInfo = session.getUser();
        String recommendCode = userInfo.getRecommendCode();
        ServiceResult<List<RewardRebate>> serviceResult = serviceFactory.getActivityService().findRewardRebateByStatus(userInfo.getId(), status==null?RewardRebateStatus.UNACTIVE:status, int_curPage, 10,startTime,endTime);
        PageUtil pageUtil = new PageUtil(10, serviceResult.getReturnListSize(), int_curPage);
        map.put("dataList", serviceResult.getReturnValue());
        map.put("PageUtil", pageUtil);
        map.put("recommendCode", recommendCode);
        map.put("status", status==null ? "UNACTIVE" : status);
        map.put("startTime", startTime == null?"":startTime);
        map.put("endTime", endTime == null?"":endTime);
        return "/page/account/reward/rewardrebate.jsp";
    }
}
